<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .title {
        background-color: pink;
      }
      .content {
        background-color: hotpink;
      }
    </style>
  </head>
  <body>
    <div id="root"></div>
    <script src="./js/react.development.js"></script>
    <script src="./js/react-dom.development.js"></script>
    <script src="./js/babel.min.js"></script>

    <script type="text/babel">
      const list = [
        { id: 1, name: 'jack', content: 'rose, you jump i jump' },
        { id: 2, name: 'rose', content: 'jack, you see you, one day day' },
        { id: 3, name: 'tom', content: 'jack,。。。。。' },
      ]

      const div = (
        <div>
          {list.length ? (
            <ul>
              {list.map((item) => {
                return (
                  <li key={item.id} style={{ backgroundColor: 'skyblue' }}>
                    <a
                      href=""
                      onClick={function (e) {
                        e.preventDefault()
                        console.log(e.target.innerText)
                        //  注意: react中我们写的事件处理函数,不是真正的事件处理函数.所以return false无效
                        return false
                      }}
                    >
                      <h3 className="title">{item.name}</h3>
                      <p className="content">{item.content}</p>
                    </a>
                  </li>
                )
              })}
            </ul>
          ) : (
            <h1>暂无评论</h1>
          )}
        </div>
      )
      ReactDOM.render(div, document.getElementById('root'))
    </script>
  </body>
</html>
